package net.tycmc.cty.ctyms.timejob.iems.dao;

import java.util.List;
import java.util.Map;

import org.apache.commons.configuration.ConfigurationException;

import com.tycmc.functions.util.DynamicReadConfig;
import com.tycmc.functions.util.MapGetter;

import net.tycmc.bulb.common.dao.IBaseDAO;
import net.tycmc.bulb.common.util.DateUtil;
import net.tycmc.bulb.common.util.StringUtil;
import net.tycmc.cty.ctyms.timejob.common.DateRegUtil;

public class DelayDataParamStatDAO {
	//用来校验是否是第一天的数据
//	private StringBuffer checkSQL = null;
//	private String today = DateUtil.addDay(0);
	private IBaseDAO baseDAO;
	public IBaseDAO getBaseDAO() {
		return baseDAO;
	}
	public void setBaseDAO(IBaseDAO baseDAO) {
		this.baseDAO = baseDAO;
	}
	/**
	 * 获取此次处理时缓存信息ID范围，并更新标志
	 **/
	public List<Map<String, Object>> getDefIDOfWorkMsgBfID() {
		String strSQL = "select fltMR_MsgF_ID as startID from fltMsgRecord  where fltMR_TableName = 'BufferRecord' order by fltMR_DBName";
		List<Map<String,Object>> srcList = this.baseDAO.execQuery(strSQL, new Object[]{});
		String readCode = "select MAX(MsgBF_ID) as maxCounts,'1' softType from CTY_Egn_A.dbo.Msg_BufferRecord union all select MAX(MsgBF_ID) as maxCounts,'2' softType from CTY_Egn_B.dbo.Msg_BufferRecord ";
		List<Map<String,Object>> tmpList = this.baseDAO.execQuery(readCode, new Object[]{});
		if(null!=tmpList && !tmpList.isEmpty() && null!=srcList && !srcList.isEmpty() && (tmpList.size() == srcList.size())){
			int[] endids = new int[2]; 
			for(Map<String,Object> map:tmpList){
				if(MapGetter.getString(map,"softType").equals("1")){
					endids[0] = Integer.parseInt(MapGetter.getString(map, "maxCounts"));
					srcList.get(0).put("endID", endids[0]);
				}else if(MapGetter.getString(map,"softType").equals("2")){
					endids[1] = Integer.parseInt(MapGetter.getString(map, "maxCounts"));
					srcList.get(1).put("endID", endids[1]);
				}
			}
			String updateSql = "update fltMsgRecord set fltMR_MsgF_ID = ?,fltMR_UpdateTime = GETDATE() where fltMR_DBName = 'A' and fltMR_TableName = 'BufferRecord';update fltMsgRecord set fltMR_MsgF_ID = ?,fltMR_UpdateTime = GETDATE() where fltMR_DBName = 'B' and fltMR_TableName = 'BufferRecord' ";
			this.baseDAO.execUpdate(updateSql, new Object[]{endids[0],endids[1]});
		}
		return  srcList;
	}
	/**
	 * 获取此次处理的 设备ID/延迟时间最长的信息时间 序列
	 * @param List<Map<String, Object>> listID list.get(0) 大一设备标志ID list.get(1)小一设备标志ID
	 **/
	public List<Map<String, Object>> queryDelayMsgOfVclTime(
			List<Map<String, Object>> listID) {
		if(null!=listID&&!listID.isEmpty()){
			String delay = "";
			try {
				delay = DynamicReadConfig.getConfigProperty("config.properties", "delayDays");
			} catch (ConfigurationException e) {
			}
			if(!StringUtil.isValid(delay)){//如果未定义delayDays 则默认为-90天
				delay = "-90";
			}
			String limitTime = DateUtil.addDay(Integer.parseInt(delay));
			StringBuffer strSQL = new StringBuffer();
			strSQL.append("select distinct tmp.*,Tmnl_SoftEdition from ( ");
			strSQL.append(" Select  MsgBF_Vcl_ID as VehicleID,convert(varchar(10),MsgBF_Time,20) as MsgTime,'1' vcltype  from CTY_Egn_A.dbo.Msg_BufferRecord abr ");
	        strSQL.append(" where abr.MsgBF_ID > ? and abr.MsgBF_ID <= ? and  abr.MsgBF_MsgTp_ID = 1 and abr.MsgBF_State = 0 and abr.MsgBF_Time >= '"+limitTime+"' ");
	        strSQL.append(" union all "); 
	        strSQL.append(" Select  MsgBF_Vcl_ID as VehicleID,convert(varchar(10),MsgBF_Time,20) as MsgTime,'2' vcltype  from CTY_Egn_B.dbo.Msg_BufferRecord bbr");
	        strSQL.append(" where bbr.MsgBF_ID > ? and bbr.MsgBF_ID < = ? and bbr.MsgBF_MsgTp_ID in (1,4,5,6) and bbr.MsgBF_State = 0 and bbr.MsgBF_Time >= '"+limitTime+"' ");
	        strSQL.append(" )tmp inner join V_VehicleInfo on V_VehicleInfo.VehicleID = tmp.VehicleID  where 1=1 and UsefulLife > GETDATE() and Tmnl_SoftEdition is not null and Tmnl_SoftEdition <> '' order by vcltype ");
			return this.baseDAO.execQuery(strSQL.toString(), new Object[]{MapGetter.getString(listID.get(0), "startID"),MapGetter.getString(listID.get(0), "endID"),MapGetter.getString(listID.get(1), "startID"),MapGetter.getString(listID.get(1), "endID")});
		}else{
			return null;
		}
	}
	/**
	 * 校验最后一条是否是延迟信息（油耗、里程、工作小时数 至少有一个不为0）
	 * @param int softType 1:大一；2:403；3:412；4：jpp设备（414及其以上）
	 **/
	public boolean checkDelayIsLast(Map<String, Object> vclTimeInfo,int softType) {
		String time = MapGetter.getString(vclTimeInfo, "MsgTime");
		String tableTime = time.replaceAll("-", "");
		String VehicleID = MapGetter.getString(vclTimeInfo, "VehicleID");
		StringBuffer strBuf = new StringBuffer();
		/*switch(softType){
		case 1://大一
			strBuf.append("select delayisLast = case when (MsgT_RcvTime > '"+time+" 23:59:59') then 1 else 0 end from  ");
			strBuf.append("(select top 1 MsgT_MsgTime from CTY_Egn_A.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = '"+VehicleID+"' ");
			strBuf.append("and (ISNULL(MsgT_tEWork,0)>0 or ISNULL(MsgT_tOilCons,0)>0 or ISNULL(MsgT_tRunKm,0)>0 or ISNULL(MsgT_tRunKm1,0)>0 or ISNULL(MsgT_tRunKmECU,0)>0 ) ");
			strBuf.append("order by MsgT_MsgTime desc) tmp where 1=1 ");
			break;
		case 2://403
			strBuf.append("select delayislast = case when (MsgC_MsgTime > '"+time+" 23:59:59' )then 1 else 0 end from ( ");
			strBuf.append("select top 1 MsgC_MsgTime from CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" mc inner join CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" mcc on mc.MsgC_ID = MsgCCo_MsgC_ID ");
			strBuf.append("where mc.MsgC_Vcl_ID = '"+VehicleID+"' and mcc.MsgCCo_SysCP_ID in (20,22,27,28,29,53) and mcc.MsgCCo_ParmValue is not null and mcc.MsgCCo_ParmValue > 0 ");
			strBuf.append("order by mc.MsgC_MsgTime desc ");
			strBuf.append(")tmp where 1=1 ");
			break;
		case 3://412
			strBuf.append("select delayislast = case when (MsgT_MsgTime > '"+time+" 23:59:59' )then 1 else 0 end from ( ");
			strBuf.append("select top 1 MsgT_MsgTime from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" ");
			strBuf.append("where MsgT_Vcl_ID = '"+VehicleID+"' and (ISNULL(MsgT_tWorkTime_UDS,0)>0 or ISNULL(MsgT_tOilCons_UDS,0)>0) order by MsgT_MsgTime desc ");
			strBuf.append("union all ");
			strBuf.append("select top 1 MsgU_MsgTime from CTY_Egn_B.dbo.Msg_UDS_"+tableTime+" inner join CTY_Egn_B.dbo.Msg_UDS_Content_"+tableTime+" on MsgUC_MsgU_ID = MsgU_ID ");
			strBuf.append("where MsgU_Vcl_ID = '"+VehicleID+"' and MsgUC_UDSID='3027' and MsgUC_UDSValue is not null order by MsgU_MsgTime desc ");
			strBuf.append(") temp  where 1=1 ");
			break;
		case 4://414及其以上
			strBuf.append("select delayislast = case when (MsgT_MsgTime > '"+time+" 23:59:59' )then 1 else 0 end from ( ");
			strBuf.append("select top 1 MsgT_MsgTime from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = '"+VehicleID+"' and ");
			strBuf.append("(ISNULL(MsgT_tWorkTime_UDS,0)>0 or ISNULL(MsgT_tOilCons_UDS,0)>0 or ISNULL(MsgT_tRunKmExact,0)>0 or ISNULL(MsgT_tRunKm,0)>0 or ISNULL(MsgT_tRunKmECU,0)>0 or ISNULL(MsgT_tRunKmExact_PGN,0)>0) order by MsgT_MsgTime desc ");
			strBuf.append("union all ");
			strBuf.append("select top 1 MsgP_MsgTime from CTY_Egn_B.dbo.Msg_PGN_"+tableTime+" inner join CTY_Egn_B.dbo.Msg_PGN_Content_"+tableTime+" on MsgP_ID=MsgPC_MsgP_ID ");
			strBuf.append("where MsgP_Vcl_ID = '"+VehicleID+"' and MsgPC_SysPIP_ID=405 and MsgPC_SysPI_ID=65 and MsgPC_PGNValue is not null order by MsgP_MsgTime desc ");
			strBuf.append(") temp  where 1=1 ");
			break;
		}
		int delayIsLast = MapGetter.getInt(this.baseDAO.execQueryOne(strBuf.toString(), new Object[]{}), "delayisLast");
		if(delayIsLast>0){
			return true;
		}else{
			return false;
		}*/
		switch(softType){
		case 1:
			strBuf.append("select  MsgT_RcvTime from  ( select top 1 MsgT_RcvTime from CTY_Egn_A.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = '"+VehicleID+"' and MsgT_tEWork is not null and MsgT_tEWork >0 order by MsgT_MsgTime desc ");
			strBuf.append("union  select top 1 MsgT_RcvTime from CTY_Egn_A.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = '"+VehicleID+"' and MsgT_tOilCons is not null and MsgT_tOilCons >0 order by MsgT_MsgTime desc  ");
			strBuf.append("union  select top 1 MsgT_RcvTime from CTY_Egn_A.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = '"+VehicleID+"' and MsgT_tRunKm is not null and MsgT_tRunKm > 0 order by MsgT_MsgTime desc  ");
			strBuf.append("union  select top 1 MsgT_RcvTime from CTY_Egn_A.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = '"+VehicleID+"' and MsgT_tRunKm1 is not null and MsgT_tRunKm1 > 0 order by MsgT_MsgTime desc  ");
			strBuf.append("union  select top 1 MsgT_RcvTime from CTY_Egn_A.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = '"+VehicleID+"' and MsgT_tRunKmECU is not null and MsgT_tRunKmECU >0 order by MsgT_MsgTime desc) tmp where 1=1 ");
			break;
		case 2:
			strBuf.append("select MsgC_RcvTime as MsgT_RcvTime from ( SELECT  top 1 MsgC_RcvTime FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 20  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = '"+VehicleID+"' order by MsgC_MsgTime desc  ");
			strBuf.append("union SELECT top 1 MsgC_RcvTime FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 22  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = '"+VehicleID+"' order by MsgC_MsgTime desc  ");
			strBuf.append("union SELECT top 1 MsgC_RcvTime FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 24  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = '"+VehicleID+"' order by MsgC_MsgTime desc  ");
			strBuf.append("union SELECT top 1 MsgC_RcvTime FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 53  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = '"+VehicleID+"' order by MsgC_MsgTime desc  ");
			strBuf.append("union SELECT top 1 MsgC_RcvTime FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 27  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = '"+VehicleID+"' order by MsgC_MsgTime desc  ");
			strBuf.append("union SELECT top 1 MsgC_RcvTime FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 28  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = '"+VehicleID+"' order by MsgC_MsgTime desc  ");
			strBuf.append("union SELECT top 1 MsgC_RcvTime FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 29  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = '"+VehicleID+"' order by MsgC_MsgTime desc ) temp where 1=1 ");
			break;
		case 3:
			strBuf.append("select MsgT_RcvTime from ( select top 1 MsgT_RcvTime from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = '"+VehicleID+"' and MsgT_tWorkTime_UDS is not null and MsgT_tWorkTime_UDS >0 order by MsgT_MsgTime desc ");
			strBuf.append("union select top 1 MsgT_RcvTime from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID ='"+VehicleID+"'  and MsgT_tOilCons_UDS is not null and MsgT_tOilCons_UDS >0 order by MsgT_MsgTime desc )temp where 1=1  ");
			break;
		case 4:
			strBuf.append("select MsgT_RcvTime from (select top 1 MsgT_RcvTime from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = '"+VehicleID+"' and MsgT_tWorkTime_UDS is not null and MsgT_tWorkTime_UDS >0 order by MsgT_MsgTime desc ");
			strBuf.append("union select top 1 MsgT_RcvTime from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = '"+VehicleID+"' and MsgT_tOilCons is not null and MsgT_tOilCons >0 order by MsgT_MsgTime desc ");
			strBuf.append("union select top 1 MsgT_RcvTime from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = '"+VehicleID+"' and MsgT_tIdleWorkTime_PGN is not null and MsgT_tIdleWorkTime_PGN >0 order by MsgT_MsgTime desc ");
			strBuf.append("union select top 1 MsgT_RcvTime from CTY_EGN_b.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = '"+VehicleID+"' and MsgT_tRunKmExact_PGN is not null and MsgT_tRunKmExact_PGN >0 order by MsgT_MsgTime desc ");
			strBuf.append("union select top 1 MsgT_RcvTime from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = '"+VehicleID+"' and MsgT_tRunKmExact is not null and MsgT_tRunKmExact >0 order by MsgT_MsgTime desc ");
			strBuf.append("union select top 1 MsgT_RcvTime from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = '"+VehicleID+"' and MsgT_tRunKm is not null and MsgT_tRunKm >0 order by MsgT_MsgTime desc ");
			strBuf.append("union select top 1 MsgT_RcvTime from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = '"+VehicleID+"' and MsgT_tRunKmECU is not null and MsgT_tRunKmECU >0 order by MsgT_MsgTime desc ) tmp where 1=1 ");
			break;
		default:
			break;
		}
		List<Map<String,Object>> srcList = this.baseDAO.execQuery(strBuf.toString(), new Object[]{});
		boolean flag = false;
		if(null!=srcList&&!srcList.isEmpty()){
			for(Map<String,Object> map:srcList){
				//只有是某一个信息的是 延迟信息， 则直接返回 true
				if(DateRegUtil.compare(MapGetter.getString(map, "MsgT_RcvTime"), time+" 23:59:59", "yyyy-MM-dd HH:mm:ss")){
					flag = true;
					break;
				}
			}
		}else{//此方法的设备ID，是由缓存信息获取的，srcList正常情况下是不可能为null的，但是为null时，按最后一条不是延迟信息处理
			
		}
		return flag;
	}
	/**
	 * 重新计算大一设备的参数统计
	 **/
	public void updateBoDelayParam(String time, String vehicleID) {
		String preTime = DateUtil.addDay(time,-1);
		String tableName = "CTY_Egn_A.dbo.Msg_Timing_"+time.replaceAll("-", "");
		StringBuffer strBuf = new StringBuffer();
		strBuf.append("update Message_Stat_TimingParam ");
		strBuf.append("set MsgSTP_iEWorkHours = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tEWork,0)) when 0 then preEWorkHours else MsgT_tEWork end - case(ISNULL(preEWorkHours,0)) when 0 then MsgT_tEWork_min else preEWorkHours end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tEWorkHours = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tEWork,0)) when 0 then preEWorkHours else MsgT_tEWork end))*1.0,2) as DECIMAL(18,2)), ");
		strBuf.append("MsgSTP_iOilCons = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tOilCons,0)) when 0 then preOilCons else MsgT_tOilCons end - case(ISNULL(preOilCons,0)) when 0 then MsgT_tOilCons_min else preOilCons end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tOilCons = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tOilCons,0)) when 0 then preOilCons else MsgT_tOilCons end))*1.0,2) as DECIMAL(18,2)), ");
//		strBuf.append("MsgSTP_iIdleOil = MsgT_iIdleOil, ");
		strBuf.append("MsgSTP_iRunKmExact = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tRunKm,0)) when 0 then preRunKmExact else MsgT_tRunKm end - case(ISNULL(preRunKmExact,0)) when 0 then MsgT_tRunKm_min else preRunKmExact end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tRunKmExact = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tRunKm,0)) when 0 then preRunKmExact else MsgT_tRunKm end))*1.0,2) as DECIMAL(18,2)), ");
		strBuf.append("MsgSTP_iRunKm = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tRunKm1,0)) when 0 then preRunKm else MsgT_tRunKm1 end - case(ISNULL(preRunKm,0)) when 0 then MsgT_tRunKm1_min else preRunKm end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tRunKm = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tRunKm1,0)) when 0 then preRunKm else MsgT_tRunKm1 end))*1.0,2) as DECIMAL(18,2)), ");
		strBuf.append("MsgSTP_iRunKmECU = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tRunKmECU,0)) when 0 then preRunKmECU else MsgT_tRunKmECU end - case(ISNULL(preRunKmECU,0)) when 0 then MsgT_tRunKmECU_min else preRunKmECU end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tRunKmECU = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tRunKmECU,0)) when 0 then preRunKmECU else MsgT_tRunKmECU end))*1.0,2) as DECIMAL(18,2)), ");
//		strBuf.append("MsgSTP_NewDate = '"+this.today+"' ");
		strBuf.append("MsgSTP_NewDate = CONVERT(varchar(10),GETDATE(),20) ");
		strBuf.append("from (select VehicleID,mst.MsgSTP_tEWorkHours as preEWorkHours, ");
		strBuf.append("mst.MsgSTP_tOilCons as preOilCons,mst.MsgSTP_tRunKmExact as preRunKmExact, ");
		strBuf.append("mst.MsgSTP_tRunKm as preRunKm,mst.MsgSTP_tRunKmECU as preRunKmECU, ");
		
		strBuf.append("MsgT_tEWork = ISNULL((select Top 1 MsgT_tEWork from "+tableName+" where MsgT_Vcl_ID = VehicleID and MsgT_tEWork is not null and MsgT_tEWork > 0 order by MsgT_MsgTime desc),0), ");
		strBuf.append("MsgT_tOilCons = ISNULL((select Top 1 MsgT_tOilCons from "+tableName+" where MsgT_Vcl_ID = VehicleID and MsgT_tOilCons is not null and MsgT_tOilCons > 0 order by MsgT_MsgTime desc),0), ");
//		strBuf.append("MsgT_iIdleOil = null, ");
		strBuf.append("MsgT_tRunKm =ISNULL((select Top 1 MsgT_tRunKm from "+tableName+" where MsgT_Vcl_ID = VehicleID and MsgT_tRunKm is not null and MsgT_tRunKm > 0 order by MsgT_MsgTime desc),0), ");
		strBuf.append("MsgT_tRunKm1 =ISNULL((select Top 1 MsgT_tRunKm1 from "+tableName+" where MsgT_Vcl_ID = VehicleID and MsgT_tRunKm1 is not null and MsgT_tRunKm1 > 0 order by MsgT_MsgTime desc),0), ");
		strBuf.append("MsgT_tRunKmECU = ISNULL((select Top 1 MsgT_tRunKmECU from "+tableName+" where MsgT_Vcl_ID = VehicleID and MsgT_tRunKmECU is not null and MsgT_tRunKmECU > 0 order by MsgT_MsgTime desc),0), ");

		strBuf.append("MsgT_tEWork_min = ISNULL((select Top 1 MsgT_tEWork from "+tableName+" where MsgT_Vcl_ID = VehicleID and MsgT_tEWork is not null and MsgT_tEWork > 0 order by MsgT_MsgTime),0), ");
		strBuf.append("MsgT_tOilCons_min = ISNULL((select Top 1 MsgT_tOilCons from "+tableName+" where MsgT_Vcl_ID = VehicleID and MsgT_tOilCons is not null and MsgT_tOilCons > 0 order by MsgT_MsgTime),0), ");
		strBuf.append("MsgT_tRunKm_min =ISNULL((select Top 1 MsgT_tRunKm from "+tableName+" where MsgT_Vcl_ID = VehicleID and MsgT_tRunKm is not null and MsgT_tRunKm > 0 order by MsgT_MsgTime),0), ");
		strBuf.append("MsgT_tRunKm1_min =ISNULL((select Top 1 MsgT_tRunKm1 from "+tableName+" where MsgT_Vcl_ID = VehicleID and MsgT_tRunKm1 is not null and MsgT_tRunKm1 > 0 order by MsgT_MsgTime),0), ");
		strBuf.append("MsgT_tRunKmECU_min = ISNULL((select Top 1 MsgT_tRunKmECU from "+tableName+" where MsgT_Vcl_ID = VehicleID and MsgT_tRunKmECU is not null and MsgT_tRunKmECU > 0 order by MsgT_MsgTime),0) ");
		
		strBuf.append("from V_VehicleInfo vv left join (select * from Message_Stat_TimingParam  where MsgSTP_VclID = '"+vehicleID+"' and MsgSTP_StatTime = '"+preTime+"' )mst on vv.VehicleID = mst.MsgSTP_VclID where VehicleID = '"+vehicleID+"' ");
		strBuf.append(")temp where temp.VehicleID = Message_Stat_TimingParam.MsgSTP_VclID and Message_Stat_TimingParam.MsgSTP_StatTime = '"+time+"' ");
		this.baseDAO.execUpdate(strBuf.toString(), new Object[]{});
		
		//校验是否是第一天的数据
		/*if(this.checkFirstTime(time,vehicleID)){
			strBuf.setLength(0);
			strBuf.append("update Message_Stat_TimingParam ");
			strBuf.append("set MsgSTP_iEWorkHours = iTime, ");
			strBuf.append("MsgSTP_iOilCons = iOil,");
			strBuf.append("MsgSTP_iRunKmExact = iRunKmExact, ");
			strBuf.append("MsgSTP_iRunKm = iRunKm, ");
			strBuf.append("MsgSTP_iRunKmECU = iRunKmECU from ( ");
			
			strBuf.append("select tmp.MsgT_tOilCons-tmp1.MsgT_tOilCons iOil, " +
					"tmp.MsgT_tEWork-tmp1.MsgT_tEWork iTime, tmp.MsgT_tRunKm-tmp1.MsgT_tRunKm iRunKmExact, " +
					"tmp.MsgT_tRunKm1-tmp1.MsgT_tRunKm1 iRunKm, tmp.MsgT_tRunKmECU-tmp1.MsgT_tRunKmECU iRunKmECU from (");
			strBuf.append("SELECT * from "+
					"(SELECT MsgT_tOilCons = ISNULL((select top 1 MsgT_tOilCons from "+tableName+" where MsgT_tOilCons is not null and MsgT_tOilCons >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime desc),0), "+
					"MsgT_tEWork = ISNULL((select top 1 MsgT_tEWork from "+tableName+" where MsgT_tEWork is not null and MsgT_tEWork >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime desc),0), "+
					"MsgT_tRunKm = ISNULL((select top 1 MsgT_tRunKm from "+tableName+" where MsgT_tRunKm is not null and MsgT_tRunKm >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime desc),0), "+
					"MsgT_tRunKm1 = ISNULL((select top 1 MsgT_tRunKm1 from "+tableName+" where MsgT_tRunKm1 is not null and MsgT_tRunKm1 >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime desc),0), "+
					"MsgT_tRunKmECU = ISNULL((select top 1 MsgT_tRunKmECU from "+tableName+" where MsgT_tRunKmECU is not null and MsgT_tRunKmECU >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime desc),0) "+
					"FROM V_VehicleInfo where VehicleID = ? ) bo0 ) tmp LEFT JOIN ( ");
			strBuf.append("SELECT * from "+
					"(SELECT MsgT_tOilCons = ISNULL((select top 1 MsgT_tOilCons from "+tableName+" where MsgT_tOilCons is not null and MsgT_tOilCons >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime asc),0), "+
					"MsgT_tEWork = ISNULL((select top 1 MsgT_tEWork from "+tableName+" where MsgT_tEWork is not null and MsgT_tEWork >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime asc),0), "+
					"MsgT_tRunKm = ISNULL((select top 1 MsgT_tRunKm from "+tableName+" where MsgT_tRunKm is not null and MsgT_tRunKm >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime asc),0), "+
					"MsgT_tRunKm1 = ISNULL((select top 1 MsgT_tRunKm1 from "+tableName+" where MsgT_tRunKm1 is not null and MsgT_tRunKm1 >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime asc),0), "+
					"MsgT_tRunKmECU = ISNULL((select top 1 MsgT_tRunKmECU from "+tableName+" where MsgT_tRunKmECU is not null and MsgT_tRunKmECU >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime asc),0) "+
					"FROM V_VehicleInfo where VehicleID = ? ) bo1 ) tmp1 ON 1 = 1 where 1=1 ");
			strBuf.append(" )tempLast where MsgSTP_VclID = ? and  MsgSTP_StatTime = ? ");
			this.baseDAO.execUpdate(strBuf.toString(), new Object[]{vehicleID,vehicleID,vehicleID,time});
		}*/
		strBuf = null;
		//更新gps里程
		this.updateDelayGPSKm(preTime,time,vehicleID);
		
	}
	/**
	 * 重新统计403设备的参数信息
	 **/
	public void updateCanDelayParam(String time, String vehicleID) {
		String preTime = DateUtil.addDay(time,-1);
		String tableTime = time.replaceAll("-", "");
		StringBuffer strBuf = new StringBuffer();
		strBuf.append("update Message_Stat_TimingParam ");
		strBuf.append("set MsgSTP_iEWorkHours = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tWorkTime_UDS,0)) when 0 then preEWorkHours else MsgT_tWorkTime_UDS end - case(ISNULL(preEWorkHours,0)) when 0 then MsgT_tWorkTime_UDS_min else preEWorkHours end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tEWorkHours = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tWorkTime_UDS,0)) when 0 then preEWorkHours else MsgT_tWorkTime_UDS end))*1.0,2) as DECIMAL(18,2)), ");
		strBuf.append("MsgSTP_iOilCons = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tOilCons,0)) when 0 then preOilCons else MsgT_tOilCons end - case(ISNULL(preOilCons,0)) when 0 then MsgT_tOilCons_min else preOilCons end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tOilCons = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tOilCons,0)) when 0 then preOilCons else MsgT_tOilCons end))*1.0,2) as DECIMAL(18,2)), ");
		strBuf.append("MsgSTP_iIdleOil = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tIdleOil,0)) when 0 then pretIdleOil else MsgT_tIdleOil end - case(ISNULL(pretIdleOil,0)) when 0 then MsgT_tIdleOil_min else pretIdleOil end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tIdleOil = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tIdleOil,0)) when 0 then pretIdleOil else MsgT_tIdleOil end))*1.0,2) as DECIMAL(18,2)), ");
		strBuf.append("MsgSTP_iMeterDistance = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tMeterDis,0)) when 0 then preMeterDistance else MsgT_tMeterDis end - case(ISNULL(preMeterDistance,0)) when 0 then MsgT_tMeterDis_min else preMeterDistance end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tMeterDistance = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tMeterDis,0)) when 0 then preMeterDistance else MsgT_tMeterDis end))*1.0,2) as DECIMAL(18,2)), ");
		strBuf.append("MsgSTP_iRunKmExact = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tRunKmExact,0)) when 0 then preRunKmExact else MsgT_tRunKmExact end - case(ISNULL(preRunKmExact,0)) when 0 then MsgT_tRunKmExact_min else preRunKmExact end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tRunKmExact = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tRunKmExact,0)) when 0 then preRunKmExact else MsgT_tRunKmExact end))*1.0,2) as DECIMAL(18,2)), ");
		strBuf.append("MsgSTP_iRunKm = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tRunKm,0)) when 0 then preRunKm else MsgT_tRunKm end - case(ISNULL(preRunKm,0)) when 0 then MsgT_tRunKm_min else preRunKm end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tRunKm = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tRunKm,0)) when 0 then preRunKm else MsgT_tRunKm end))*1.0,2) as DECIMAL(18,2)), ");
		strBuf.append("MsgSTP_iRunKmECU = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tRunKmECU,0)) when 0 then preRunKmECU else MsgT_tRunKmECU end - case(ISNULL(preRunKmECU,0)) when 0 then MsgT_tRunKmECU_min else preRunKmECU end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tRunKmECU = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tRunKmECU,0)) when 0 then preRunKmECU else MsgT_tRunKmECU end))*1.0,2) as DECIMAL(18,2)),");
		strBuf.append("MsgSTP_iIdleTime = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tIdleTime,0)) when 0 then preTidleTime else MsgT_tIdleTime end - case(ISNULL(preTidleTime,0)) when 0 then MsgT_tIdleTime_min else preTidleTime end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tIdleTime = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tIdleTime,0)) when 0 then preTidleTime else MsgT_tIdleTime end))*1.0,2) as DECIMAL(18,2)), ");
//		strBuf.append("MsgSTP_NewDate = '"+this.today+"' ");
		strBuf.append("MsgSTP_NewDate = CONVERT(varchar(10),GETDATE(),20) ");
		strBuf.append("from(select VehicleID,MsgSTP_tEWorkHours as preEWorkHours, MsgSTP_tOilCons as preOilCons,MsgSTP_tIdleOil as pretIdleOil, MsgSTP_tMeterDistance as preMeterDistance, ");
		strBuf.append("MsgSTP_tRunKmExact as preRunKmExact,MsgSTP_tRunKm as preRunKm,MsgSTP_tRunKmECU as preRunKmECU ,MsgSTP_tIdleTime as preTidleTime, ");
		
		strBuf.append("MsgT_tWorkTime_UDS = ISNULL((SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 20  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime desc),0), ");
		strBuf.append("MsgT_tOilCons = ISNULL((SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 22  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime desc),0), ");
		strBuf.append("MsgT_tIdleOil = ISNULL((SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 24  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime desc),0), ");
		strBuf.append("MsgT_tMeterDis = ISNULL((SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 53  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime desc),0), ");
		strBuf.append("MsgT_tRunKmExact = ISNULL((SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 27  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime desc),0), ");
		strBuf.append("MsgT_tRunKm = ISNULL((SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 28  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime desc),0), ");
		strBuf.append("MsgT_tRunKmECU = ISNULL((SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 29  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime desc),0), ");
		strBuf.append("MsgT_tIdleTime = ISNULL((SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 25  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime desc),0), ");
		
		strBuf.append("MsgT_tWorkTime_UDS_min = ISNULL((SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 20  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime),0), ");
		strBuf.append("MsgT_tOilCons_min = ISNULL((SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 22  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime),0), ");
		strBuf.append("MsgT_tIdleOil_min = ISNULL((SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 24  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime),0), ");
		strBuf.append("MsgT_tMeterDis_min = ISNULL((SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 53  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime ),0), ");
		strBuf.append("MsgT_tRunKmExact_min = ISNULL((SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 27  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime),0), ");
		strBuf.append("MsgT_tRunKm_min = ISNULL((SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 28  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime),0), ");
		strBuf.append("MsgT_tRunKmECU_min = ISNULL((SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 29  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime),0), ");
		strBuf.append("MsgT_tIdleTime_min = ISNULL((SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID WHERE  MsgCCo_SysCP_ID = 25  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime),0) ");
		
		strBuf.append("from V_VehicleInfo vv left join (select * from Message_Stat_TimingParam  where MsgSTP_VclID = '"+vehicleID+"' and MsgSTP_StatTime = '"+preTime+"' )mst on vv.VehicleID = mst.MsgSTP_VclID where VehicleID = '"+vehicleID+"' ");
		strBuf.append(")tmp where Message_Stat_TimingParam.MsgSTP_VclID = VehicleID and Message_Stat_TimingParam.MsgSTP_StatTime = '"+time+"' ");
		this.baseDAO.execUpdate(strBuf.toString(), new Object[]{});
		
		//校验是否是第一天的数据
		/*if(this.checkFirstTime(time,vehicleID)){
			strBuf.setLength(0);
			StringBuffer paramSql_SO = new StringBuffer();
			paramSql_SO.append("select tmp.ECM-tmp1.ECM iTime,tmp.tOilCons-tmp1.tOilCons iOil,tmp.tKm4-tmp1.tKm4 iMeterDistance,tmp.tKm1-tmp1.tKm1 iRunKmExact,tmp.tKm2-tmp1.tKm2 iRunKm,tmp.tKm3-tmp1.tKm3 iRunKmECU from (");
			paramSql_SO.append("select VehicleID,ECM = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID ");
			paramSql_SO.append("WHERE  MsgCCo_SysCP_ID = 20  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime desc), ");
			paramSql_SO.append("tOilCons = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID ");
			paramSql_SO.append("WHERE  MsgCCo_SysCP_ID = 22  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime desc), ");
			paramSql_SO.append("tKm1= (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID ");
			paramSql_SO.append("WHERE  MsgCCo_SysCP_ID = 27  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime desc), ");
			paramSql_SO.append("tKm2 = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+"  INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID ");
			paramSql_SO.append("WHERE  MsgCCo_SysCP_ID = 28  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime desc), ");
			paramSql_SO.append("tKm3 = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+"  INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID ");
			paramSql_SO.append("WHERE  MsgCCo_SysCP_ID = 29  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime desc), ");
			paramSql_SO.append("tKm4 = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID ");
			paramSql_SO.append("WHERE  MsgCCo_SysCP_ID = 53  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime desc) ");
			paramSql_SO.append("FROM  v_vehicleinfo AS vehicleinfo where VehicleID = ? ) tmp ");
			paramSql_SO.append("LEFT JOIN (select VehicleID, ECM = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID ");
			paramSql_SO.append("WHERE  MsgCCo_SysCP_ID = 20  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime asc), ");
			paramSql_SO.append("tOilCons = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID ");
			paramSql_SO.append("WHERE  MsgCCo_SysCP_ID = 22  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime asc), ");
			paramSql_SO.append("tKm1= (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID ");
			paramSql_SO.append("WHERE  MsgCCo_SysCP_ID = 27  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime asc), ");
			paramSql_SO.append("tKm2 = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID ");
			paramSql_SO.append("WHERE  MsgCCo_SysCP_ID = 28  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime asc), ");
			paramSql_SO.append("tKm3 = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID ");
			paramSql_SO.append("WHERE  MsgCCo_SysCP_ID = 29  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime asc), ");
			paramSql_SO.append("tKm4 = (SELECT  top 1 MsgCCo_ParmValue FROM  CTY_Egn_B.dbo.Msg_CAN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_CAN_Content_"+tableTime+" ON MsgC_ID = MsgCCo_MsgC_ID ");
			paramSql_SO.append("WHERE  MsgCCo_SysCP_ID = 53  and MsgCCo_ParmValue is not null and MsgCCo_ParmValue>0  AND MsgC_Vcl_ID = VehicleID order by MsgC_MsgTime asc)  ");
			paramSql_SO.append("FROM  v_vehicleinfo AS vehicleinfo where VehicleID = ? ) tmp1 ON 1 = 1  where 1=1 ");
			
			Map<String,Object> paramMapSub = baseDAO.execQueryOne(paramSql_SO.toString(),new Object[]{vehicleID,vehicleID});
			
			strBuf.append("update Message_Stat_TimingParam set MsgSTP_iEWorkHours = ?,MsgSTP_iOilCons = ?,MsgSTP_iMeterDistance = ?,");
			strBuf.append("MsgSTP_iRunKmExact = ?,MsgSTP_iRunKm = ?,MsgSTP_iRunKmECU = ? where MsgSTP_VclID = '"+vehicleID+"' and MsgSTP_StatTime = '"+time+"' ");
			this.baseDAO.execUpdate(strBuf.toString(), new Object[]{
				this.getFloat(paramMapSub, "iTime"),this.getFloat(paramMapSub, "iOil"),this.getFloat(paramMapSub, "iMeterDistance"),
				this.getFloat(paramMapSub, "iRunKmExact"),this.getFloat(paramMapSub, "iRunKm"),this.getFloat(paramMapSub, "iRunKmECU"),
			});
		}*/
		strBuf = null;
		//更新gps里程
		this.updateDelayGPSKm(preTime,time,vehicleID);
	}
	/**
	 * 重新统计412设备的参数信息
	 **/
	public void updatePPDelayParam(String time, String vehicleID) {
		String preTime = DateUtil.addDay(time,-1);
		String tableTime = time.replaceAll("-", "");
		StringBuffer strBuf = new StringBuffer();
		strBuf.append("update Message_Stat_TimingParam ");
		strBuf.append("set MsgSTP_iEWorkHours = case(ISNULL(MsgT_tWorkTime_UDS,0)) when 0 then preEWorkHours else MsgT_tWorkTime_UDS end - case(ISNULL(preEWorkHours,0)) when 0 then MsgT_tWorkTime_UDS_min else preEWorkHours end,MsgSTP_tEWorkHours = case(ISNULL(MsgT_tWorkTime_UDS,0)) when 0 then preEWorkHours else MsgT_tWorkTime_UDS end, ");
		strBuf.append("MsgSTP_iOilCons = case(ISNULL(MsgT_tOilCons,0)) when 0 then preOilCons else MsgT_tOilCons end - case(ISNULL(preOilCons,0)) when 0 then MsgT_tOilCons_min else preOilCons end,MsgSTP_tOilCons = case(ISNULL(MsgT_tOilCons,0)) when 0 then preOilCons else MsgT_tOilCons end, ");
//		strBuf.append("MsgSTP_iIdleOil = MsgT_iIdleOil, ");
		strBuf.append("MsgSTP_iMeterDistance = case(ISNULL(MsgT_tMeterDis,0)) when 0 then preMeterDistance else MsgT_tMeterDis end - case(ISNULL(preMeterDistance,0)) when 0 then MsgT_tMeterDis_min else preMeterDistance end,MsgSTP_tMeterDistance = case(ISNULL(MsgT_tMeterDis,0)) when 0 then preMeterDistance else MsgT_tMeterDis end, ");
//		strBuf.append("MsgSTP_NewDate = '"+this.today+"' ");
		strBuf.append("MsgSTP_NewDate = CONVERT(varchar(10),GETDATE(),20) ");
		strBuf.append("from (select VehicleID,MsgSTP_tEWorkHours as preEWorkHours, MsgSTP_tOilCons as preOilCons, MsgSTP_tMeterDistance as preMeterDistance, ");
		strBuf.append("MsgT_tWorkTime_UDS = ISNULL((select top 1 MsgT_tWorkTime_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and MsgT_tWorkTime_UDS is not null and MsgT_tWorkTime_UDS >0 order by MsgT_MsgTime desc ),0), ");
		strBuf.append("MsgT_tOilCons = ISNULL((select top 1 MsgT_tOilCons_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and MsgT_tOilCons_UDS is not null and MsgT_tOilCons_UDS >0 order by MsgT_MsgTime desc ),0), ");
//		strBuf.append("MsgT_iIdleOil = null, ");
		strBuf.append("MsgT_tMeterDis = ISNULL((select top 1 CONVERT(float,MsgUC_UDSValue) as MsgU_tMeterDis from CTY_Egn_B.dbo.Msg_UDS_"+tableTime+" inner join  CTY_Egn_B.dbo.Msg_UDS_Content_"+tableTime+" on MsgUC_MsgU_ID = MsgU_ID  where  MsgU_Vcl_ID = VehicleID and MsgUC_UDSID='3027' and MsgUC_UDSValue is not null and CONVERT(float,MsgUC_UDSValue)>0 order by MsgU_MsgTime desc),0), ");
		
		strBuf.append("MsgT_tWorkTime_UDS_min = ISNULL((select top 1 MsgT_tWorkTime_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and MsgT_tWorkTime_UDS is not null and MsgT_tWorkTime_UDS >0 order by MsgT_MsgTime),0), ");
		strBuf.append("MsgT_tOilCons_min = ISNULL((select top 1 MsgT_tOilCons_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and MsgT_tOilCons_UDS is not null and MsgT_tOilCons_UDS >0 order by MsgT_MsgTime),0), ");
		strBuf.append("MsgT_tMeterDis_min = ISNULL((select top 1 CONVERT(float,MsgUC_UDSValue) as MsgU_tMeterDis from CTY_Egn_B.dbo.Msg_UDS_"+tableTime+" inner join  CTY_Egn_B.dbo.Msg_UDS_Content_"+tableTime+" on MsgUC_MsgU_ID = MsgU_ID  where  MsgU_Vcl_ID = VehicleID and MsgUC_UDSID='3027' and MsgUC_UDSValue is not null and CONVERT(float,MsgUC_UDSValue)>0 order by MsgU_MsgTime),0) ");
		
		strBuf.append("from V_VehicleInfo vv left join (select * from Message_Stat_TimingParam  where MsgSTP_VclID = '"+vehicleID+"' and MsgSTP_StatTime = '"+preTime+"' )mst on vv.VehicleID = mst.MsgSTP_VclID where VehicleID = '"+vehicleID+"' ");
		strBuf.append(")tmp where Message_Stat_TimingParam.MsgSTP_VclID = VehicleID and Message_Stat_TimingParam.MsgSTP_StatTime = '"+time+"' ");
		this.baseDAO.execUpdate(strBuf.toString(), new Object[]{});
		
		//校验是否是第一天的数据
		/*if(this.checkFirstTime(time,vehicleID)){
			strBuf.setLength(0);
			StringBuffer paramKmSql = new StringBuffer("select tmp.MsgT_tOilCons_UDS-tmp1.MsgT_tOilCons_UDS iOil,");
			paramKmSql.append("tmp.MsgT_tWorkTime_UDS-tmp1.MsgT_tWorkTime_UDS iTime,CONVERT(float,tmp.MsgT_tMeter)-CONVERT(float,tmp1.MsgT_tMeter) iMeterDistance from ");
			paramKmSql.append("(SELECT MsgT_tOilCons_UDS =(select top 1 MsgT_tOilCons_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where  MsgT_tOilCons_UDS is not null and MsgT_tOilCons_UDS >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime desc), ");
			paramKmSql.append("MsgT_tWorkTime_UDS =(select top 1 MsgT_tWorkTime_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where  MsgT_tWorkTime_UDS is not null and MsgT_tWorkTime_UDS >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime desc), ");
			paramKmSql.append("MsgT_tMeter = (select MsgUC_UDSValue from  CTY_Egn_B.dbo.Msg_UDS_Content_"+tableTime+" where MsgUC_ID = ( select MAX(MsgUC_ID) from CTY_Egn_B.dbo.Msg_UDS_"+tableTime+" inner join CTY_Egn_B.dbo.Msg_UDS_Content_"+tableTime+"  on MsgUC_MsgU_ID=MsgU_ID where MsgUC_UDSID='3027' and MsgUC_UDSValue is not null  and MsgU_Vcl_ID= VehicleID)) ");
			paramKmSql.append("FROM  V_VehicleInfo where VehicleID = ?) tmp LEFT JOIN ( ");
			paramKmSql.append("SELECT MsgT_tOilCons_UDS =(select top 1 MsgT_tOilCons_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where  MsgT_tOilCons_UDS is not null and MsgT_tOilCons_UDS >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime asc),");
			paramKmSql.append("MsgT_tWorkTime_UDS =(select top 1 MsgT_tWorkTime_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where  MsgT_tWorkTime_UDS is not null and MsgT_tWorkTime_UDS >0 and MsgT_Vcl_ID = VehicleID order by MsgT_MsgTime asc),");
			paramKmSql.append("MsgT_tMeter = (select MsgUC_UDSValue from  CTY_Egn_B.dbo.Msg_UDS_Content_"+tableTime+" where MsgUC_ID = ( select MIN(MsgUC_ID) from CTY_Egn_B.dbo.Msg_UDS_"+tableTime+" inner join CTY_Egn_B.dbo.Msg_UDS_Content_"+tableTime+"  on MsgUC_MsgU_ID=MsgU_ID where MsgUC_UDSID='3027' and MsgUC_UDSValue is not null  and MsgU_Vcl_ID= VehicleID)) ");
			paramKmSql.append("FROM  V_VehicleInfo where VehicleID = ?) tmp1 ON 1 = 1 where 1=1 ");
			Map<String,Object> paramMap = baseDAO.execQueryOne(paramKmSql.toString(), new Object[]{vehicleID,vehicleID});
			strBuf.append("update Message_Stat_TimingParam set MsgSTP_iEWorkHours = ?,MsgSTP_iOilCons = ?,MsgSTP_iMeterDistance = ? where MsgSTP_VclID = '"+vehicleID+"' and MsgSTP_StatTime = '"+time+"' ");
			this.baseDAO.execUpdate(strBuf.toString(), new Object[]{
				this.getFloat(paramMap, "iTime"),this.getFloat(paramMap, "iOil"),this.getFloat(paramMap, "iMeterDistance")
			});
		}*/
		strBuf = null;
		//更新gps里程
		this.updateDelayGPSKm(preTime,time,vehicleID);
	}
	/**
	 * 重新统计414设备的参数信息
	 **/
	public void updateJPPDelayParam(String time, String vehicleID) {
		String preTime = DateUtil.addDay(time,-1);
		String tableTime = time.replaceAll("-", "");
		StringBuffer strBuf = new StringBuffer();
		strBuf.append("update Message_Stat_TimingParam ");
/*		strBuf.append("set MsgSTP_iEWorkHours = MsgT_tWorkTime_UDS-case(ISNULL(preEWorkHours,0)) when 0 then (888888+MsgT_tWorkTime_UDS) else preEWorkHours end,MsgSTP_tEWorkHours = MsgT_tWorkTime_UDS, ");
		strBuf.append("MsgSTP_iOilCons = MsgT_tOilCons-case(ISNULL(preOilCons,0)) when 0 then (888888+MsgT_tOilCons) else preOilCons end,MsgSTP_tOilCons = MsgT_tOilCons, ");
		strBuf.append("MsgSTP_iMeterDistance = MsgT_tMeterDis-case(ISNULL(preMeterDistance,0)) when 0 then (888888+MsgT_tMeterDis) else preMeterDistance end,MsgSTP_tMeterDistance = MsgT_tMeterDis, ");
		strBuf.append("MsgSTP_iRunKmExact = MsgT_tRunKmExact - case(ISNULL(preRunKmExact,0)) when 0 then (888888+MsgT_tRunKmExact) else preRunKmExact end,MsgSTP_tRunKmExact = MsgT_tRunKmExact, ");
		strBuf.append("MsgSTP_iRunKm = MsgT_tRunKm-case(ISNULL(preRunKm,0)) when 0 then (888888+MsgT_tRunKm) else preRunKm end,MsgSTP_tRunKm = MsgT_tRunKm, ");
		strBuf.append("MsgSTP_iRunKmECU = MsgT_tRunKmECU-case(ISNULL(preRunKmECU,0)) when 0 then (888888+MsgT_tRunKmECU) else preRunKmECU end,MsgSTP_tRunKmECU = MsgT_tRunKmECU,");
*/
		strBuf.append("set MsgSTP_iEWorkHours = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tWorkTime_UDS,0)) when 0 then preEWorkHours else MsgT_tWorkTime_UDS end-case(ISNULL(preEWorkHours,0)) when 0 then MsgT_tWorkTime_UDS_min else preEWorkHours end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tEWorkHours = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tWorkTime_UDS,0)) when 0 then preEWorkHours else MsgT_tWorkTime_UDS end))*1.0,2) as DECIMAL(18,2)), ");
		strBuf.append("MsgSTP_iOilCons = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tOilCons,0)) when 0 then preOilCons else MsgT_tOilCons end-case(ISNULL(preOilCons,0)) when 0 then MsgT_tOilCons_min else preOilCons end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tOilCons = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tOilCons,0)) when 0 then preOilCons else MsgT_tOilCons end))*1.0,2) as DECIMAL(18,2)), ");
		strBuf.append("MsgSTP_iIdleOil = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tIdleOil,0)) when 0 then preIdleOil else MsgT_tIdleOil end-case(ISNULL(preIdleOil,0)) when 0 then MsgT_tIdleOil_min else preIdleOil end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tIdleOil = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tIdleOil,0)) when 0 then preIdleOil else MsgT_tIdleOil end))*1.0,2) as DECIMAL(18,2)), ");
		strBuf.append("MsgSTP_iMeterDistance = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tMeterDis,0)) when 0 then preMeterDistance else MsgT_tMeterDis end - case(ISNULL(preMeterDistance,0)) when 0 then MsgT_tMeterDis_min else preMeterDistance end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tMeterDistance = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tMeterDis,0)) when 0 then preMeterDistance else MsgT_tMeterDis end))*1.0,2) as DECIMAL(18,2)), ");
		strBuf.append("MsgSTP_iRunKmExact = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tRunKmExact,0)) when 0 then preRunKmExact else MsgT_tRunKmExact end - case(ISNULL(preRunKmExact,0)) when 0 then MsgT_tRunKmExact_min else preRunKmExact end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tRunKmExact = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tRunKmExact,0)) when 0 then preRunKmExact else MsgT_tRunKmExact end))*1.0,2) as DECIMAL(18,2)), ");
		strBuf.append("MsgSTP_iRunKm = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tRunKm,0)) when 0 then preRunKm else MsgT_tRunKm end - case(ISNULL(preRunKm,0)) when 0 then MsgT_tRunKm_min else preRunKm end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tRunKm = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tRunKm,0)) when 0 then preRunKm else MsgT_tRunKm end))*1.0,2) as DECIMAL(18,2)), ");
		strBuf.append("MsgSTP_iRunKmECU = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tRunKmECU,0)) when 0 then preRunKmECU else MsgT_tRunKmECU end-case(ISNULL(preRunKmECU,0)) when 0 then MsgT_tRunKmECU_min else preRunKmECU end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tRunKmECU = Cast(round(Convert(FLOAT,MsgT_tRunKmECU)*1.0,2) as DECIMAL(18,2)),");
		
		strBuf.append("MsgSTP_iIdleTime = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tIdleTime,0)) when 0 then preTidleTime else MsgT_tIdleTime end - case(ISNULL(preTidleTime,0)) when 0 then MsgT_tIdleTime_min else preTidleTime end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tIdleTime = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tIdleTime,0)) when 0 then preTidleTime else MsgT_tIdleTime end))*1.0,2) as DECIMAL(18,2)), ");
		strBuf.append("MsgSTP_iUraeValue = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tUraeValue,0)) when 0 then preTureaValue else MsgT_tUraeValue end-case(ISNULL(preTureaValue,0)) when 0 then MsgT_tRunKmECU_min else preTureaValue end))*1.0,2) as DECIMAL(18,2)),MsgSTP_tUraeValue = Cast(round(Convert(FLOAT,(case(ISNULL(MsgT_tUraeValue,0)) when 0 then preTureaValue else MsgT_tUraeValue end))*1.0,2) as DECIMAL(18,2)),");
		
//		strBuf.append("MsgSTP_NewDate = '"+this.today+"' ");
		strBuf.append("MsgSTP_NewDate = CONVERT(varchar(10),GETDATE(),20) ");
		strBuf.append("from (select VehicleID,MsgSTP_tEWorkHours as preEWorkHours, MsgSTP_tOilCons as preOilCons, MsgSTP_tIdleOil as preIdleOil,MsgSTP_tMeterDistance as preMeterDistance, ");
		strBuf.append("MsgSTP_tRunKmExact as preRunKmExact,MsgSTP_tRunKm as preRunKm,MsgSTP_tRunKmECU as preRunKmECU ,MsgSTP_tIdleTime as preTidleTime,MsgSTP_tUraeValue as preTureaValue, ");
		
		strBuf.append("MsgT_tWorkTime_UDS = ISNULL((select top 1 MsgT_tWorkTime_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and MsgT_tWorkTime_UDS is not null and MsgT_tWorkTime_UDS >0 order by MsgT_MsgTime desc ),0), ");
		strBuf.append("MsgT_tOilCons = ISNULL((select top 1 MsgT_tOilCons from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and MsgT_tOilCons is not null and MsgT_tOilCons >0 order by MsgT_MsgTime desc ),0), ");
		strBuf.append("MsgT_tIdleOil = ISNULL((select top 1 MsgT_tIdleWorkTime_PGN from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and MsgT_tIdleWorkTime_PGN is not null and MsgT_tIdleWorkTime_PGN >0 order by MsgT_MsgTime desc),ISNULL((select top 1 CONVERT(float,MsgPC_PGNValue) as MsgP_tIdleOil from  CTY_Egn_B.dbo.Msg_PGN_"+tableTime+" inner join CTY_Egn_B.dbo.Msg_PGN_Content_"+tableTime+" on MsgP_ID=MsgPC_MsgP_ID where MsgP_Vcl_ID = VehicleID and MsgPC_SysPIP_ID=11 and MsgPC_SysPI_ID=8 and MsgPC_PGNValue is not null  and CONVERT(float,MsgPC_PGNValue)>0 order by MsgP_MsgTime desc),0)), ");
//		调整jpp设备 仪表里程 参数信息取值的逻辑， 20140815 jiyongtian cty 1688
		strBuf.append("MsgT_tMeterDis = ISNULL((select top 1 MsgT_tRunKmExact_PGN from CTY_EGN_b.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and MsgT_tRunKmExact_PGN is not null and MsgT_tRunKmExact_PGN >0 order by MsgT_MsgTime desc),ISNULL((select top 1 CONVERT(float,MsgPC_PGNValue) as MsgP_tMeterDis from CTY_Egn_B.dbo.Msg_PGN_"+tableTime+" inner join CTY_Egn_B.dbo.Msg_PGN_Content_"+tableTime+" on MsgP_ID = MsgPC_MsgP_ID where MsgP_Vcl_ID = VehicleID and MsgPC_SysPIP_ID=405 and MsgPC_SysPI_ID=65 and MsgPC_PGNValue is not null and CONVERT(float,MsgPC_PGNValue)>0 order by MsgP_MsgTime desc),0)), ");
		strBuf.append("MsgT_tRunKmExact = ISNULL((select top 1 MsgT_tRunKmExact from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and MsgT_tRunKmExact is not null and MsgT_tRunKmExact >0 order by MsgT_MsgTime desc ),0), ");		
		strBuf.append("MsgT_tRunKm = ISNULL((select top 1 MsgT_tRunKm from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and MsgT_tRunKm is not null and MsgT_tRunKm >0 order by MsgT_MsgTime desc ),0), ");
		strBuf.append("MsgT_tRunKmECU = ISNULL((select top 1 MsgT_tRunKmECU from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and MsgT_tRunKmECU is not null and MsgT_tRunKmECU >0 order by MsgT_MsgTime desc ),0), ");
		
		strBuf.append("MsgT_tIdleTime = ISNULL((select top 1 MsgT_tIdleWorkTime_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and MsgT_tIdleWorkTime_UDS is not null and MsgT_tIdleWorkTime_UDS >0 order by MsgT_MsgTime desc ),ISNULL((select top 1 CONVERT(float,MsgPC_PGNValue) as MsgT_tIdleTime from  CTY_Egn_B.dbo.Msg_PGN_"+tableTime+" inner join CTY_Egn_B.dbo.Msg_PGN_Content_"+tableTime+" on MsgP_ID=MsgPC_MsgP_ID where MsgP_Vcl_ID = VehicleID and MsgPC_SysPIP_ID=12 and MsgPC_SysPI_ID=8 and MsgPC_PGNValue is not null  and CONVERT(float,MsgPC_PGNValue)>0 order by MsgP_MsgTime desc),0)), ");
		strBuf.append("MsgT_tUraeValue = ISNULL((select top 1 CONVERT(float,MsgUC_UDSValue) as MsgT_tUraeValue from CTY_Egn_B.dbo.Msg_UDS_"+tableTime+" inner join  CTY_Egn_B.dbo.Msg_UDS_Content_"+tableTime+" on MsgUC_MsgU_ID = MsgU_ID  where  MsgU_Vcl_ID = VehicleID and MsgUC_UDSID='B7E2' and MsgUC_UDSValue is not null and CONVERT(float,MsgUC_UDSValue)>0 order by MsgU_MsgTime desc),0), ");
		
		strBuf.append("MsgT_tWorkTime_UDS_min = ISNULL((select top 1 MsgT_tWorkTime_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and MsgT_tWorkTime_UDS is not null and MsgT_tWorkTime_UDS >0 order by MsgT_MsgTime),0), ");
		strBuf.append("MsgT_tOilCons_min = ISNULL((select top 1 MsgT_tOilCons from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and MsgT_tOilCons is not null and MsgT_tOilCons >0 order by MsgT_MsgTime ),0), ");
		strBuf.append("MsgT_tIdleOil_min = ISNULL((select top 1 MsgT_tIdleWorkTime_PGN from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and MsgT_tIdleWorkTime_PGN is not null and MsgT_tIdleWorkTime_PGN >0 order by MsgT_MsgTime),ISNULL((select top 1 CONVERT(float,MsgPC_PGNValue) as MsgP_tIdleOil from CTY_Egn_B.dbo.Msg_PGN_"+tableTime+" inner join CTY_Egn_B.dbo.Msg_PGN_Content_"+tableTime+" on MsgP_ID=MsgPC_MsgP_ID where MsgP_Vcl_ID = VehicleID and MsgPC_SysPIP_ID=11 and MsgPC_SysPI_ID=8 and MsgPC_PGNValue is not null and CONVERT(float,MsgPC_PGNValue) >0 order by MsgP_MsgTime),0)), ");
//		strBuf.append("MsgT_tMeterDis_min = ISNULL((select top 1 MsgT_tRunKmExact_PGN from CTY_EGN_b.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = mst.MsgSTP_VclID and MsgT_tRunKmExact_PGN is not null and MsgT_tRunKmExact_PGN >0 order by MsgT_MsgTime),ISNULL((select CONVERT(float,MsgPC_PGNValue) as MsgP_tMeterDis from CTY_Egn_B.dbo.Msg_PGN_Content_"+tableTime+" where MsgPC_ID = (select MIN(MsgPC_ID) from CTY_Egn_B.dbo.Msg_PGN_"+tableTime+" inner join CTY_Egn_B.dbo.Msg_PGN_Content_"+tableTime+" on MsgP_ID=MsgPC_MsgP_ID where  MsgPC_SysPIP_ID=405 and MsgPC_SysPI_ID=65 and MsgPC_PGNValue is not null and MsgP_Vcl_ID = mst.MsgSTP_VclID)),0)), ");
		strBuf.append("MsgT_tMeterDis_min = ISNULL((select top 1 MsgT_tRunKmExact_PGN from CTY_EGN_b.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and MsgT_tRunKmExact_PGN is not null and MsgT_tRunKmExact_PGN >0 order by MsgT_MsgTime),ISNULL((select top 1 CONVERT(float,MsgPC_PGNValue) as MsgP_tMeterDis from CTY_Egn_B.dbo.Msg_PGN_"+tableTime+" inner join CTY_Egn_B.dbo.Msg_PGN_Content_"+tableTime+" on MsgP_ID = MsgPC_MsgP_ID where MsgP_Vcl_ID = VehicleID and MsgPC_SysPIP_ID=405 and MsgPC_SysPI_ID=65 and MsgPC_PGNValue is not null and CONVERT(float,MsgPC_PGNValue)>0 order by MsgP_MsgTime),0)), ");
		strBuf.append("MsgT_tRunKmExact_min = ISNULL((select top 1 MsgT_tRunKmExact from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and MsgT_tRunKmExact is not null and MsgT_tRunKmExact >0 order by MsgT_MsgTime ),0), ");
		strBuf.append("MsgT_tRunKm_min = ISNULL((select top 1 MsgT_tRunKm from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and MsgT_tRunKm is not null and MsgT_tRunKm >0 order by MsgT_MsgTime),0), ");
		strBuf.append("MsgT_tRunKmECU_min = ISNULL((select top 1 MsgT_tRunKmECU from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and MsgT_tRunKmECU is not null and MsgT_tRunKmECU >0 order by MsgT_MsgTime),0), ");
		
		strBuf.append("MsgT_tIdleTime_min = ISNULL((select top 1 MsgT_tIdleWorkTime_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and MsgT_tIdleWorkTime_UDS is not null and MsgT_tIdleWorkTime_UDS >0 order by MsgT_MsgTime ),ISNULL((select top 1 CONVERT(float,MsgPC_PGNValue) as MsgT_tIdleTime from  CTY_Egn_B.dbo.Msg_PGN_"+tableTime+" inner join CTY_Egn_B.dbo.Msg_PGN_Content_"+tableTime+" on MsgP_ID=MsgPC_MsgP_ID where MsgP_Vcl_ID = VehicleID and MsgPC_SysPIP_ID=12 and MsgPC_SysPI_ID=8 and MsgPC_PGNValue is not null  and CONVERT(float,MsgPC_PGNValue)>0 order by MsgP_MsgTime),0)), ");
		strBuf.append("MsgT_tUraeValue_min = ISNULL((select top 1 CONVERT(float,MsgUC_UDSValue) as MsgT_tUraeValue from CTY_Egn_B.dbo.Msg_UDS_"+tableTime+" inner join  CTY_Egn_B.dbo.Msg_UDS_Content_"+tableTime+" on MsgUC_MsgU_ID = MsgU_ID  where  MsgU_Vcl_ID = VehicleID and MsgUC_UDSID='B7E2' and MsgUC_UDSValue is not null and CONVERT(float,MsgUC_UDSValue)>0 order by MsgU_MsgTime),0) ");
		
		strBuf.append("from V_VehicleInfo vv left join (select * from Message_Stat_TimingParam  where MsgSTP_VclID = '"+vehicleID+"' and MsgSTP_StatTime = '"+preTime+"' )mst on vv.VehicleID = mst.MsgSTP_VclID where VehicleID = '"+vehicleID+"' ");
		strBuf.append(")tmp where Message_Stat_TimingParam.MsgSTP_VclID = tmp.VehicleID and Message_Stat_TimingParam.MsgSTP_StatTime = '"+time+"'");
		this.baseDAO.execUpdate(strBuf.toString(), new Object[]{});
		
		//校验是否是第一天的数据
		/*if(this.checkFirstTime(time,vehicleID)){
			strBuf.setLength(0);
			StringBuffer paramKmSqlSub = new StringBuffer();//查询油耗、工作小时数、高精度里程、ecm里程
			paramKmSqlSub.append("select tmp.MsgT_tOilCons-tmp1.MsgT_tOilCons iOil,tmp.MsgT_tWorkTime_UDS-tmp1.MsgT_tWorkTime_UDS iTime,");						
			paramKmSqlSub.append("tmp.MsgT_tRunKmExact-tmp1.MsgT_tRunKmExact iRunKmExact,tmp.tRunKm-tmp1.tRunKm iRunKm ");
			paramKmSqlSub.append("from (select MsgT_tOilCons = (select top 1 MsgT_tOilCons from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and  MsgT_tOilCons is not null and MsgT_tOilCons >0  order by MsgT_MsgTime desc),");
			paramKmSqlSub.append("MsgT_tWorkTime_UDS = (select top 1 MsgT_tWorkTime_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and  MsgT_tWorkTime_UDS is not null and MsgT_tWorkTime_UDS >0  order by MsgT_MsgTime desc), ");
			paramKmSqlSub.append("MsgT_tRunKmExact = (select top 1 MsgT_tRunKmExact from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and  MsgT_tRunKmExact is not null and MsgT_tRunKmExact >0  order by MsgT_MsgTime desc),");
			paramKmSqlSub.append("tRunKm = (select top 1 MsgT_tRunKm from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and  MsgT_tRunKm is not null and MsgT_tRunKm >0  order by MsgT_MsgTime desc) ");
			paramKmSqlSub.append(" from V_VehicleInfo where VehicleID = ?)tmp left join (select ");
			paramKmSqlSub.append("MsgT_tOilCons = (select top 1 MsgT_tOilCons from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and  MsgT_tOilCons is not null and MsgT_tOilCons >0  order by MsgT_MsgTime ASC),");
			paramKmSqlSub.append("MsgT_tWorkTime_UDS = (select top 1 MsgT_tWorkTime_UDS from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and  MsgT_tWorkTime_UDS is not null and MsgT_tWorkTime_UDS >0  order by MsgT_MsgTime ASC),");
			paramKmSqlSub.append("MsgT_tRunKmExact = (select top 1 MsgT_tRunKmExact from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and  MsgT_tRunKmExact is not null and MsgT_tRunKmExact >0  order by MsgT_MsgTime asc),");
			paramKmSqlSub.append("tRunKm = (select top 1 MsgT_tRunKm from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and  MsgT_tRunKm is not null and MsgT_tRunKm >0  order by MsgT_MsgTime asc) ");
			paramKmSqlSub.append(" from V_VehicleInfo where VehicleID = ? )tmp1 on 1=1 where 1=1 ");
			
			StringBuffer paramKmSqlElse = new StringBuffer();//ecu里程、仪表里程
			paramKmSqlElse.append("select tmp.MsgT_tRunKmECU-tmp1.MsgT_tRunKmECU iRunKmECU, tmp.MsgT_tRunKmExact_PGN-tmp1.MsgT_tRunKmExact_PGN iRunKmExact_PGN ");
			paramKmSqlElse.append("from (select MsgT_tRunKmECU = (select top 1 MsgT_tRunKmECU  from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and  MsgT_tRunKmECU is not null and MsgT_tRunKmECU >0  order by MsgT_MsgTime desc),");
			paramKmSqlElse.append("MsgT_tRunKmExact_PGN = case when MsgT_tRunKmExact_PGN IS not null and MsgT_tRunKmExact_PGN >0 then MsgT_tRunKmExact_PGN ");
			paramKmSqlElse.append("else ISNULL(MsgP_tMeterDis,0) end ");
			paramKmSqlElse.append("from V_VehicleInfo left join CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" on VehicleID= MsgT_Vcl_ID and MsgT_ID = (select MAX(MsgT_ID) from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_tRunKmExact_PGN is not null and MsgT_Vcl_ID = ? ) ");
			paramKmSqlElse.append("left join ( SELECT MsgP_Vcl_ID, Convert(FLOAT,MsgPC_PGNValue) AS MsgP_tMeterDis FROM  CTY_Egn_B.dbo.Msg_PGN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_PGN_Content_"+tableTime+" ON MsgP_ID = MsgPC_MsgP_ID and MsgPC_ID = ( SELECT Max(MsgPC_ID) MsgPC_ID  From CTY_Egn_B.dbo.Msg_PGN_"+tableTime+" inner join CTY_Egn_B.dbo.Msg_PGN_Content_"+tableTime+" on MsgPC_MsgP_ID = MsgP_ID WHERE MsgPC_SysPIP_ID = 405 AND MsgPC_SysPI_ID = 65 AND MsgPC_PGNValue IS NOT NULL  and MsgP_Vcl_ID = ? ))temp_meter on temp_meter.MsgP_Vcl_ID = VehicleID ");
			paramKmSqlElse.append("where VehicleID = ?)tmp left join (select MsgT_tRunKmECU = (select top 1 MsgT_tRunKmECU  from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_Vcl_ID = VehicleID and MsgT_tRunKmECU is not null and MsgT_tRunKmECU >0  order by MsgT_MsgTime asc),");
			paramKmSqlElse.append("MsgT_tRunKmExact_PGN = case when MsgT_tRunKmExact_PGN IS not null and MsgT_tRunKmExact_PGN >0 then MsgT_tRunKmExact_PGN ");
			paramKmSqlElse.append("else ISNULL(MsgP_tMeterDis,0) end ");
			paramKmSqlElse.append("from V_VehicleInfo left join CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" on VehicleID=MsgT_Vcl_ID and MsgT_ID = (select MIN(MsgT_ID) from CTY_Egn_B.dbo.Msg_Timing_"+tableTime+" where MsgT_tRunKmExact_PGN is not null and MsgT_tRunKmExact_PGN>0 and MsgT_Vcl_ID = ?) ");
			paramKmSqlElse.append("left join ( SELECT MsgP_Vcl_ID, Convert(FLOAT,MsgPC_PGNValue) AS MsgP_tMeterDis FROM  CTY_Egn_B.dbo.Msg_PGN_"+tableTime+" INNER JOIN CTY_Egn_B.dbo.Msg_PGN_Content_"+tableTime+" ON MsgP_ID = MsgPC_MsgP_ID and MsgPC_ID in ( SELECT Min(MsgPC_ID) MsgPC_ID  From CTY_Egn_B.dbo.Msg_PGN_"+tableTime+" inner join CTY_Egn_B.dbo.Msg_PGN_Content_"+tableTime+" on MsgPC_MsgP_ID = MsgP_ID WHERE MsgPC_SysPIP_ID = 405 AND MsgPC_SysPI_ID = 65 AND MsgPC_PGNValue IS NOT NULL  and MsgP_Vcl_ID = ? ))temp_meter on temp_meter.MsgP_Vcl_ID = VehicleID ");
			paramKmSqlElse.append("where VehicleID = ? )tmp1 on 1=1 where 1=1 ");
			Map<String,Object> paramMapSub = baseDAO.execQueryOne(paramKmSqlSub.toString(), new Object[]{vehicleID,vehicleID});
			Map<String,Object> paramMapElse = baseDAO.execQueryOne(paramKmSqlElse.toString(), new Object[]{vehicleID,vehicleID,vehicleID,vehicleID,vehicleID,vehicleID});
			
			strBuf.append("update Message_Stat_TimingParam set MsgSTP_iEWorkHours = ?,MsgSTP_iOilCons = ?,MsgSTP_iMeterDistance = ?,");
			strBuf.append("MsgSTP_iRunKmExact = ?,MsgSTP_iRunKm = ?,MsgSTP_iRunKmECU = ? where MsgSTP_VclID = '"+vehicleID+"' and MsgSTP_StatTime = '"+time+"' ");
			this.baseDAO.execUpdate(strBuf.toString(), new Object[]{
				this.getFloat(paramMapSub, "iTime"),this.getFloat(paramMapSub, "iOil"),this.getFloat(paramMapElse, "iRunKmExact_PGN"),
				this.getFloat(paramMapSub, "iRunKmExact"),this.getFloat(paramMapSub, "iRunKm"),this.getFloat(paramMapElse, "iRunKmECU"),
			});
		}*/
		strBuf = null;
		//更新gps里程
		this.updateDelayGPSKm(preTime,time,vehicleID);
	}
	/**
	 * 更新设备、日期  gps里程信息，因为gps里程信息是不分软件版本号的，所有的设备都一样的逻辑，所以单独为一个方法
	 * @更新历史 jiyongtian 20141016 GPS里程计算逻辑变更
	 **/
	private void updateDelayGPSKm(String preTime,String time, String vehicleID) {
		/*String tableTime = time.replaceAll("-", "");
		StringBuffer update = new StringBuffer();
		StringBuffer strGPSquery = new StringBuffer();
		strGPSquery.append(" select vp2.VclP_Vcl_ID as vclid,MAX(CAST(round(convert(float,ISNULL(vp2.VclP_IMileage,0))*1.0,2) as decimal(18,2))) as igpsdistance,");
		strGPSquery.append(" MAX(CAST(round(convert(float,ISNULL(vp2.VclP_TMileage,0))*1.0,2) as decimal(18,2))) as tgpsdistance ");
		strGPSquery.append(" from ((select VclP_Vcl_ID,max(vclp_id) as vclp_id  from CTY_Vcl.dbo.Vcl_Pstn_"+tableTime);
		strGPSquery.append(" where VclP_MsgTp_ID=2 and vclp_imileage >0 and VclP_Vcl_ID='"+vehicleID+"' group by VclP_Vcl_ID " +
				" union all  SELECT  vclp_vcl_id,Max(vclp_id) AS vclp_id FROM  cty_vcl.dbo.vcl_pstn_"+tableTime+
				" WHERE vclp_msgtp_id = 2 AND vclp_tmileage > 0 AND vclp_vcl_id = '"+vehicleID+"' GROUP BY vclp_vcl_id ) as vp1 left join ");	
		strGPSquery.append(" (select vclP_ID,VclP_Vcl_ID,VclP_IMileage = case when VclP_IMileage is NULL then 0 else VclP_IMileage end ,");
		strGPSquery.append(" VclP_TMileage  = case when VclP_TMileage is NULL then 0 else VclP_TMileage end ,VclP_MsgTp_ID ");
		strGPSquery.append(" from CTY_Vcl.dbo.Vcl_Pstn_"+tableTime+" ) vp2 on vp1.VclP_Vcl_ID = vp2.VclP_Vcl_ID and vp1.vclp_id = vp2.vclP_ID");
		strGPSquery.append(" left join V_VehicleInfo on vp1.VclP_Vcl_ID = VehicleID ) GROUP BY vp2.VclP_Vcl_ID ");
		Map<String,Object> gpsmap = baseDAO.execQueryOne(strGPSquery.toString(), new Object[]{});
		String igpsdistance; 
		if(null != gpsmap.get("igpsdistance")){
			igpsdistance = gpsmap.get("igpsdistance").toString();
		}else{
			igpsdistance="";
		}
		String tgpsdistance ;
		if(null != gpsmap.get("tgpsdistance") ){
			tgpsdistance = gpsmap.get("tgpsdistance").toString();
		}else{
			tgpsdistance="";
		}
		if(StringUtil.isValid(igpsdistance)&&StringUtil.isValid(tgpsdistance)){
			if(Float.parseFloat(tgpsdistance)!= 0){
				update.append("update Message_Stat_TimingParam set MsgSTP_iGPSDistance = "+igpsdistance+", MsgSTP_tGPSDistance = "+tgpsdistance+"  where MsgSTP_VclID = '"+vehicleID+"' and  MsgSTP_StatTime = '"+time+"' ");
			}else{
				String preSQL="select MsgSTP_tGPSDistance as msgstp_tgpsdistance,MsgSTP_VclID as vclid  from Message_Stat_TimingParam where MsgSTP_StatTime='"+preTime+"' and MsgSTP_VclID ='"+vehicleID+"'";
				Map<String,Object> pretemp = this.baseDAO.execQueryOne(preSQL, new Object[]{});
				if(null!=pretemp.get("msgstp_tgpsdistance")){
					update.append("update Message_Stat_TimingParam set MsgSTP_iGPSDistance = "+igpsdistance+", MsgSTP_tGPSDistance = "+pretemp.get("msgstp_tgpsdistance").toString()+"  where MsgSTP_VclID = '"+vehicleID+"' and  MsgSTP_StatTime = '"+time+"' ");
				}else{
					update.append("update Message_Stat_TimingParam set MsgSTP_iGPSDistance = "+igpsdistance+", MsgSTP_tGPSDistance = "+tgpsdistance+"  where MsgSTP_VclID = '"+vehicleID+"' and  MsgSTP_StatTime = '"+time+"' ");
				}
			}
		}else{
			String preSQL="select MsgSTP_tGPSDistance as msgstp_tgpsdistance,MsgSTP_VclID as vclid  from Message_Stat_TimingParam where MsgSTP_StatTime='"+preTime+"' and MsgSTP_VclID ='"+vehicleID+"' ";
			Map<String,Object> pre = this.baseDAO.execQueryOne(preSQL, new Object[]{});
			if(null!=pre.get("msgstp_tgpsdistance")){
				update.append("update Message_Stat_TimingParam set MsgSTP_iGPSDistance = 0,MsgSTP_tGPSDistance = "+pre.get("msgstp_tgpsdistance").toString()+" where MsgSTP_VclID = '"+vehicleID+"' and  MsgSTP_StatTime = '"+time+"' ");
			}else{
				update.append("update Message_Stat_TimingParam set MsgSTP_iGPSDistance = 0,MsgSTP_tGPSDistance = 0 where MsgSTP_VclID = '"+vehicleID+"' and  MsgSTP_StatTime = '"+time+"' ");
			}
		}
		this.baseDAO.execUpdate(update.toString(), new Object[]{});
		*/
		StringBuffer gps = new StringBuffer();
		String tableDate = time.replaceAll("-", "");
		gps.append("update Message_Stat_TimingParam set MsgSTP_iGPSDistance=temp.iGPSDistance,MsgSTP_tGPSDistance=temp.tGPSDistance ");
		gps.append("from(select tmp.VehicleID,CAST(round(convert(float,ISNULL(VclP_TMileage-VclP_TMileage_min,0))*1.0,2) as decimal(18,2)) as iGPSDistance, ");
		gps.append("tGPSDistance = case when VclP_TMileage is not null and VclP_TMileage>0 then VclP_TMileage else ISNULL(tmp.MsgSTP_tGPSDistance,0) end  ");
		gps.append("from ( select vv.VehicleID, ");
		gps.append("VclP_TMileage = (select top 1 VclP_TMileage from CTY_Vcl.dbo.Vcl_Pstn_"+tableDate+" where VclP_Vcl_ID = VehicleID and VclP_TMileage is not null and VclP_TMileage > 0 order by VclP_PstnTime desc), ");
		gps.append("VclP_TMileage_min = case when (0=isnull(mst.MsgSTP_tGPSDistance,0)) then (select top 1 VclP_TMileage from CTY_Vcl.dbo.Vcl_Pstn_"+tableDate+" where VclP_Vcl_ID = VehicleID and VclP_TMileage is not null and VclP_TMileage > 0 order by VclP_PstnTime) else mst.MsgSTP_tGPSDistance end,  ");
		gps.append("mst.MsgSTP_tGPSDistance from V_VehicleInfo vv  ");
		gps.append("left join (select * from Message_Stat_TimingParam where MsgSTP_StatTime = ? ) mst on mst.MsgSTP_VclID = VehicleID   ");
		gps.append("where  VehicleID = '"+vehicleID+"' and UsefulLife>=GETDATE() and Tmnl_SoftEdition is not null and Tmnl_SoftEdition <> '' )tmp  ");
		gps.append(")temp where MsgSTP_StatTime = ? and temp.VehicleID = MsgSTP_VclID ");
		this.baseDAO.execUpdate(gps.toString(), new Object[]{preTime,time});
	}
	/**
	 * 校验处理的设备、日期 信息是否是该设备的第一天数据
	 *
	private boolean checkFirstTime(String time, String vehicleID) {
		if(null == this.checkSQL){
			this.checkSQL = new StringBuffer();
		}
		if(this.checkSQL.toString().length()<1){
			this.checkSQL.append("select COUNT(1) as counts from Message_Stat_TimingParam where MsgSTP_VclID = ? and MsgSTP_StatTime = ? and  ");
			this.checkSQL.append("(MsgSTP_iEWorkHours = -888888 or MsgSTP_iOilCons = -888888 or MsgSTP_iMeterDistance = -888888 ");
			this.checkSQL.append("or MsgSTP_iRunKmExact = -888888 or MsgSTP_iRunKm = -888888 or MsgSTP_iRunKmECU = -888888) ");
		}
		int count = MapGetter.getInt(this.baseDAO.execQueryOne(this.checkSQL.toString(), new Object[]{vehicleID,time}),"counts");
		if(count>0){
			return true;
		}else{
			return false;
		}
	}
	private float getFloat(Map<String,Object> map,String key){
		try{
			if(StringUtil.isNullOrEmpty(MapGetter.getString(map, key))){
				return Float.parseFloat(MapGetter.getString(map, key));
			}else{
				return 0;
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		return 0;
	}*/
}